import { Id } from "../types/type.ts";
import { pool, query } from "../db/index.ts";
import { SYSTEM_TABLE } from "../db/config";

export const getUser = async (params: string[], callback: Function) => {
  const sqlStr = `SELECT * FROM ${SYSTEM_TABLE.USER} where id = ?`;

  try {
    const results: any = await query(sqlStr, params);
    callback(results[0]);
  } catch (error: any) {
    throw error;
  }
};

export const hasUser = async (params: string[], callback: Function) => {
  const sqlStr = `SELECT * FROM ${SYSTEM_TABLE.USER} WHERE user_name = ? AND password = ?`;

  try {
    const results: any[] = await query(sqlStr, params);
    callback(results.length > 0);
  } catch (error: any) {
    throw error;
  }
};
